#version 430 core

layout(local_size_x=256) in;

layout(binding=0) coherent buffer inVector1Buffer
{
	float inVector1[];
};

layout(binding=1) coherent buffer inVector2Buffer
{
	float inVector2[];
};

layout(binding=2) coherent buffer outVectorBuffer
{
	float outVector[];
};

layout(binding=3) coherent buffer scalarBuffer
{
	float scalar[];
};

uniform uint scalarID;
uniform uint numRows;
uniform float factor;

shared float totalFactor;

void main(void)
{
	uint rowID = gl_GlobalInvocationID.x;
	if (gl_LocalInvocationID.x == 0)
	{
		totalFactor = factor * scalar[scalarID];
	}

	memoryBarrierShared();
	barrier();
	
	if (rowID < numRows)
	{
		outVector[rowID] = inVector1[rowID] + totalFactor * inVector2[rowID];
	}
}